/***************************************** 
 * Desc: UGUI画布Inspector
*****************************************/

using Common.UGUI.Base;
using Common.UGUI.View;
using UnityEditor;
using UnityEngine;

namespace Common.UserEditor.UGUIViewSpace {

	[CustomEditor(typeof(UGUICanvas))]
	[CanEditMultipleObjects]
	public class UGUICanvasInspector : Editor {

        public override void OnInspectorGUI() {

			UnityEngine.Object[] objects = targets;
			int len = objects.Length;
			UGUICanvas[] canvases = new UGUICanvas[len];
			for (int i = 0; i < len; ++i) {
				canvases[i] = (UGUICanvas)objects[i];
			}

			UGUIViewOnValueCallback callbacks = new UGUIViewOnValueCallback();

			callbacks.Target = canvases;

			callbacks.SetActiveCallback = OnCanvasGottenIsActive;

			UGUIViewInspector.ShowUGUIView(canvases, base.OnInspectorGUI, callbacks);

			//GUILayout.Space(UnityEditorCommonConfig.GUILayoutGapSpace);

			ShowUGUICanvas(canvases);
		}

        #region 自定义子面板

        private static void ShowUGUICanvas(UGUICanvas[] canvases) {

			UGUICanvas canvas = canvases[0];

			GUILayout.BeginVertical();

			GUILayout.Label("CanvasLayerType:", UGUIViewInspector.UGUIViewStatusLabel, GUILayout.ExpandHeight(false));

			GUILayout.BeginHorizontal();
			GUILayout.Space(UGUIViewInspector.UITabLength);

			CanvasLayerType canvasLayerType = (CanvasLayerType)EditorGUILayout.EnumPopup(canvas.CanvasLayerType, GUILayout.ExpandWidth(false));
			foreach(var oneCanvas in canvases) {
				oneCanvas.CanvasLayerType = canvasLayerType;
			}

			GUILayout.EndHorizontal();

			GUILayout.EndVertical();
		}

		#endregion

		#region 自定义回调函数

		private void OnCanvasGottenIsActive(UGUIView[] views, bool isActive) {

			UGUICanvas[] canvases = views as UGUICanvas[];

			foreach (var oneCanvas in canvases) {
				oneCanvas.SetEditorActive(isActive);
			}
		}

		#endregion
	}
}
